﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading;
using LLoger;
using Limitator;


namespace EpdGoLimitCorrector
{
    class ConsoleLogWriter : FileLogWriter
    {
        public ConsoleLogWriter(string fileName, int maxSize) :
            base(fileName, maxSize)
        {
        }

        public override void WriteLine(string val)
        {
            base.WriteLine(val);
            Console.WriteLine(val);
        }
    }

    class Program
    {
        private LimitManager _limitator;
        private ILogWriter _logWriter = new ConsoleLogWriter("EpdGoLimitCorrector.log", 0);
        private const string _cfgFile = "limitator.config";
        private static Timer timer;

        protected Program()
        {
            try
            {
                _limitator = new LimitManager(_cfgFile, _logWriter);
                _limitator.InitializeServices();
                _logWriter.WriteLine("Старт и инициализация успешны");
            }
            catch (Exception ex)
            {
                _logWriter.WriteLine(ex, "Ошибка инициализации");
            }
        }

        protected void StartProcess()
        {

            try
            {
                _limitator.StartProcess();

                _logWriter.WriteLine("Лимиты скорректированы и выгружены в новый файл");
            }
            catch (Exception ex)
            {
                _logWriter.WriteLine(ex, "Оишбка в процессе выполнения");
            }


        }


        static void Main(string[] args)
        {
            Program prog = new Program();
            prog.StartProcess();
            Console.Write("Завершение...");
        }
    }
}
